<template>
  <u-popup round="8" :show="show" mode="center" closeable @open="open" @close="updateShow(false)">
    <view class="p-15">
      <view class="text-16 mb-12">备注</view>
      <view class="cu-textarea" style="width: 560rpx;">
        <textarea v-model="content" auto-focus maxlength="500" />
      </view>
      <view class="flex mt-20">
        <view class="flex-1"><u-button text="取消" @click="updateShow(false)" /></view>
        <view class="flex-1 ml-12"><u-button type="primary" text="保存" @click="save" /></view>
      </view>
    </view>
  </u-popup>
</template>

<script setup>
import { ref, defineProps, defineEmits } from 'vue'
import $ from '@/sheep'
const props = defineProps({
  show: Boolean,
  text: String,
  current: Number
})
const emit = defineEmits(['update:show', 'done'])
const content = ref('')

function open() {
  content.value = props.text
}

function updateShow(value = false) {
  emit('update:show', value)
}

function save() {
  const data = {
    id: props.current,
    remark: content.value
  }
  $.post('/Store/remarkCart', data).then(res => {
    $.utils.toast(res.msg)
    if (res.success) {
      emit('done', data)
      updateShow(false)
    }
  })
}
</script>
